package com.dzxcqmxm.servlet.user;

import com.dzxcqmxm.Dao.UserDao;
import com.dzxcqmxm.Dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Payboi
 * @create 2022/6/2-21:59
 * @FileName delUserServlet
 * @Description
 */
@WebServlet("/delUserServlet")
public class delUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDao userDao = new UserDaoImpl();
        try {
            //我删除数据得通过id删除记录嘛对吧，然后这里获得的参数就是首页附带的那个参数
            String UserName = request.getParameter("UserName");

            try {
                userDao.delUser(UserName);
            } catch (Exception e) {
                e.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        response.sendRedirect("/dzxc/indexUserServlet");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
